﻿@page "/model/update/{Id}"
@inject IModelService ModelService
@inject NavigationManager NavigationManager
<PageTitle>更新模型</PageTitle>
<span class="fs-5">更新 @_modelDto.Name 产品模型</span>

<EditForm Model="_modelDto" OnSubmit="Save">
    <div class="input-group mb-2">
        <span class="input-group-text">模型名称</span>
        <input class="form-control" placeholder="Name" @bind-value="@_modelDto.Name" />
    </div>
    <div class="input-group mb-2">
        <span class="input-group-text">工作量</span>
        <input class="form-control" type="number" step="0.1" @bind-value="@_modelDto.Workload" />
    </div>
    
    <div class="input-group mb-2">
        <span class="input-group-text">排序号</span>
        <input class="form-control" type="number" @bind-value="@_modelDto.SequenceNumber" />
    </div>
    
    <CompSaveCancelButtons CancelUrl="categories" />
</EditForm>



@code {
    [Parameter]
    public string Id { get; set; }

    private ModelDto _modelDto = new();
    protected override async Task OnInitializedAsync()
    {
        var response = await ModelService.GetFirstOrDefaultAsync(Guid.Parse(Id));
        if (!response.Status) NavigationManager.NavigateTo("categories");
        _modelDto = response.Result;
    }
    private async Task Save()
    {
        var result = await ModelService.UpdateAsync(Guid.Parse(Id), _modelDto);
        if (result.IsSuccessStatusCode) NavigationManager.NavigateTo("categories");
    }
}